package fun.hijklmn.magic.statistic.server.service.impl;

import com.alibaba.fastjson.JSONObject;
import fun.hijklmn.magic.statistic.server.pojo.ResourceStatistic;
import fun.hijklmn.magic.statistic.server.service.MQService;
import fun.hijklmn.magic.statistic.server.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Author fs
 * @Date 2021/6/3 14:05
 * @Version 0.0.1-SNAPSHOT
 **/
@Service
public class MQServiceImpl implements MQService {

    @Autowired
    private StatisticService statisticService;

    @Override
    @KafkaListener(id = "mqService", topics = "resource-statistic")
    public void listener(String message) {
        JSONObject jsonObject = JSONObject.parseObject(message);
        ResourceStatistic resourceStatistic = jsonObject.toJavaObject(ResourceStatistic.class);
        statisticService.statistic(resourceStatistic);
    }

}
